package com.atguigu.lease.app.service.impl;

import com.atguigu.lease.app.mapper.ApartmentFacilityMapper;
import com.atguigu.lease.app.mapper.ApartmentFeeValueMapper;
import com.atguigu.lease.app.mapper.ApartmentInfoMapper;
import com.atguigu.lease.app.mapper.ApartmentLabelMapper;
import com.atguigu.lease.app.service.*;
import com.atguigu.lease.model.bean.*;
import com.atguigu.lease.model.enums.ItemTypeEnum;
import com.atguigu.lease.model.vo.*;
import com.atguigu.lease.model.vo.app.ApartmentDetailVo;
import com.atguigu.lease.model.vo.app.ApartmentItemVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author 1
* @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
* @createDate 2025-06-20 14:04:43
*/
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
    implements ApartmentInfoService {
    @Autowired
    ApartmentFacilityMapper apartmentFacilityMapper;
    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        ApartmentItemVo apartmentItemVo = baseMapper.selectApartmentItemVo(id);
        ApartmentDetailVo vo = new ApartmentDetailVo();
        //将查询到的 公寓的详情拷贝给vo对象
        //  属性值如果拷贝失败，问题一般是： 缺少getter/setter方法、 属性名不一致、属性类型不一致
        BeanUtils.copyProperties(apartmentItemVo, vo);
        // 图片类型不一样需要我们转换后手动设置给vo
        List<GraphVo> graphVoList = apartmentItemVo.getGraphVoList().stream()
                .map(graphInfo -> {
                    GraphVo graphVo = new GraphVo();
                    BeanUtils.copyProperties(graphInfo, graphVo);
                    return graphVo;
                }).collect(Collectors.toList());
        vo.setGraphVoList(graphVoList);


        //为vo对象查询 配套信息
        List<FacilityInfo> facilityInfos =   apartmentFacilityMapper.selectFacilityInfosByApartmentId(id);
        vo.setFacilityInfoList(facilityInfos);
        return vo;
    }
}




